<template>
    <div class="lego-range">
        <div class="lego-range-row">
            <span>最小值：</span>
            <el-input-number v-model="minValue" :disabled="props.disabled" :min="0" @change="changeMinValue" />
        </div>
        <div class="lego-range-row">
            <span>最大值：</span>
            <el-input-number v-model="maxValue" :min="0" :disabled="props.disabled" @change="changeMaxValue" />
        </div>
    </div>
</template>

<script setup lang="ts">
import {ElInputNumber} from 'element-plus';
import {get} from 'lodash-es';
import {ref, unref, defineModel} from 'vue';

const modelValue = defineModel<Array<number>>();

const props = defineProps({
    disabled: Boolean
});

const emit = defineEmits(['update:modelValue']);

const minValue = ref(get(modelValue.value, '0') || 0);
const maxValue = ref(get(modelValue.value, '1') || 0);

const updateValue = () => {
    const min = unref(minValue);
    const max = unref(maxValue);
    modelValue.value = [min, max];
    emit('update:modelValue', [min, max]);
};
const changeMinValue = (val) => {
    minValue.value = val;
    updateValue();
};
const changeMaxValue = (val) => {
    maxValue.value = val;
    updateValue();
};
</script>

<style lang="less" scoped>
@import '../css/lib.less';

.lego-range {
    display: inline-block;
    .lego-range-row {
        margin-bottom: 10px;
        height: 32px;
        line-height: 32px;
        width: 300px;
        .veui-input {
            width: 230px;
        }
    }
}
</style>
